package com.pm.controller.official;

import com.pm.common.Response;
import com.pm.common.annotation.CurrentUser;
import com.pm.common.annotation.MyLog;
import com.pm.common.annotation.UserLoginToken;
import com.pm.common.exception.ExpCodeState;
import com.pm.entity.po.official.OfficialRankStatistics;
import com.pm.entity.po.security.User;
import com.pm.service.official.OfficialRankStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: pm_info_api
 * @description: 党政一把手排名统计
 * @author: xzj
 * @create: 2020-08-19 17:43
 **/
@Api(tags = "党政一把手排名统计")
@UserLoginToken
@RestController
@RequestMapping("/OfficialRankStatistics")
public class OfficialRankStatisticsController {
    @Autowired
    OfficialRankStatisticsService officialRankStatisticsService;

    @ApiOperation("新增接口")
    @PostMapping("/add")
    @ResponseBody
    @MyLog(value = "党政一把手排名统计")
    public Response<Integer> add(@RequestBody OfficialRankStatistics officialRankStatistics, @CurrentUser User user) {
        Response<Integer> response = null;
        officialRankStatistics.setAddUser(user.getUserId());
        officialRankStatistics.setEditUser(user.getUserId());
        Integer result = officialRankStatisticsService.addOne(officialRankStatistics);
        if (result > 0) {
            response = new Response<>(ExpCodeState.add_data_success, result);
        } else {
            response = new Response<>(ExpCodeState.add_data_failed);
        }
        return response;
    }

    @ApiOperation("全部列表查询接口")
    @PostMapping("/getList")
    @ResponseBody
    public Response<List<OfficialRankStatistics>> getList(@RequestBody OfficialRankStatistics officialRankStatistics) {
        List<OfficialRankStatistics> result = officialRankStatisticsService.getList(officialRankStatistics);
        Response<List<OfficialRankStatistics>> res = new Response<List<OfficialRankStatistics>>(ExpCodeState.query_data_success, result);
        return res;
    }
}
